<?php
namespace app\index\controller;

use app\index\controller\Base;
use app\common\model\Banner as BannerModel;
use app\common\model\Article as ArticleModel;
use app\common\model\Category as CategoryModel;

class Index extends Base
{
    public function index()
    {
        $BannerModel = new BannerModel();
        $banners = $BannerModel->userTypeSelect('home');
        $this->assign('banners', $banners);

        $CategoryModel = new CategoryModel();
        $category_tree = $CategoryModel->treeView(true);
        $ArticleModel = new ArticleModel();
        $top_cats = [
            'news' => 7,
            'notice' => 5,
            'research' => 4,
        ];
        foreach ($top_cats as $name => $limit_count) {
            if(isset($category_tree[$name])){
                $cat_item = $category_tree[$name];
                $list = $ArticleModel->hotList($cat_item['id'], $limit_count);
            }else{
                $list = [];
            }
            $this->assign($name, $list->all());
        }

        $this->setPageSeo(['title' => '首页']);
        return $this->fetch();
    }

    // public function demo(){
    //     $BannerModel = new BannerModel();
    //     $links = $BannerModel->userTypeSelect('link', 0);
    //     return json($links);
    // }
}
